package com.webdemo05.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateHandler {
	private static SessionFactory sessionFactory;
	private ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
	static {
		sessionFactory = new Configuration().configure().buildSessionFactory();
	}
	public static HibernateHandler newInstance() {
		return new HibernateHandler();
	}
	public Session getCurrentSession() {
		Session session = threadLocal.get();
		if (session == null) {
			session = sessionFactory.openSession();
		}
		return session;
	}
	public Session getSession() {
		Session session = sessionFactory.openSession();
		return session;
	}
}
